package com.health.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.health.system.entity.HealthRules;
import com.health.system.entity.HealthSuggestions;
import com.health.system.mapper.HealthRulesMapper;
import com.health.system.mapper.HealthSuggestionsMapper;
import com.health.system.service.HealthRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2024-06-22
 */
@Service
public class HealthRulesServiceImp extends ServiceImpl<HealthRulesMapper, HealthRules> implements HealthRulesService {

    @Autowired
    private HealthRulesMapper healthRulesMapper;
    @Autowired
    private HealthSuggestionsMapper healthSuggestionsMapper;

    @Override
    public IPage<HealthRules> getAllHealthRules(Long current, Long size) {
        IPage<HealthRules> page = new Page<>(current, size);
        return healthRulesMapper.selectPage(page, null);
    }

    @Override
    public HealthRules getHealthRulesById(Integer id) {
        return healthRulesMapper.selectById(id);
    }

    @Override
    public void addHealthRules(HealthRules healthRules) {
        healthRulesMapper.insert(healthRules);
    }

    @Override
    public void updateHealthRules(HealthRules healthRules) {
        healthRulesMapper.updateById(healthRules);
    }

    @Override
    public void deleteHealthRules(Integer id) {
        healthRulesMapper.deleteById(id);
        healthSuggestionsMapper.delete(new LambdaQueryWrapper<HealthSuggestions>()
                .eq(HealthSuggestions::getHealthRuleId, id));
    }
}
